package nz.ac.massey.jbuif.view;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 * Custom ListRender 
 * @author ahkiouma
 */
public class CustomListRender extends JLabel implements ListCellRenderer {
	private static final long serialVersionUID = 1L;
	private float[] newColor;

	
	/**
	 * rendering custom list
	 */
	public CustomListRender() {
		setOpaque(true);
        setHorizontalAlignment(LEFT);
        setVerticalAlignment(CENTER);
        newColor = Color.RGBtoHSB(104, 145, 232, null);
    }
	
	
	/**
	 * controlling the list cell rendering
	 */
	@Override
	public Component getListCellRendererComponent(JList arg0, Object arg1,
			int arg2, boolean arg3, boolean arg4) {
		//Custom Cell viewer, use to display Class type at start
       
        if (arg3) {
            setBackground(Color.getHSBColor(newColor[0], newColor[1], newColor[2]));
            setForeground(Color.WHITE);
        } else {
            setBackground(Color.WHITE);
            setForeground(Color.BLACK);
        }

        String name = arg1.getClass().getName();
        String[] nameList = name.split("\\.");
        
        //System.out.println("name is "+arg1.getClass().getName()+"   "+nameList.length);
        String itemName = (!arg1.toString().equals("") || arg1.toString() != null) ? arg1.toString() : "No String Representation Available" ;
        this.setText("<html><b>"+nameList[nameList.length-1]+":</b> "+itemName+"</html>");
        
        return this;
	}
}
